package com.gp.service.impl;

import com.gp.dao.TbCarTypeConfugDetaDao;
import com.gp.service.CarConfigService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gp.entity.TbCarTypeConfigDetails;
import com.gp.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service("carConfigService")
public class CarConfigServiceImpl implements CarConfigService {
    @Autowired(required = false)
    private TbCarTypeConfugDetaDao tbCarTypeConfugDetaDao;

    @Override
    public CommonResult findAllConfig(Integer page, Integer limit, String typename) {
        Page<TbCarTypeConfigDetails> page1=new Page<>(page,limit);
        QueryWrapper<TbCarTypeConfigDetails> wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(typename)){
            wrapper.like("typename",typename);
        }
        Page<TbCarTypeConfigDetails> page2 = tbCarTypeConfugDetaDao.selectPage(page1, wrapper);
        return new CommonResult(200,"查询成功",page2);
    }

    @Override
    public CommonResult deleteById(Integer id) {
        int i = tbCarTypeConfugDetaDao.deleteById(id);
        if (i > 0) {
            return new CommonResult(200, "删除成功", null);
        } else {
            return new CommonResult(500, "删除失败", null);
        }
    }

    @Override
    public CommonResult insertCarConfig(TbCarTypeConfigDetails details) {
        int insert = tbCarTypeConfugDetaDao.insert(details);
        if (insert > 0) {
            return new CommonResult(200, "添加成功", null);
        } else {
            return new CommonResult(500, "添加失败", null);
        }
    }

    @Override
    public CommonResult upateCarConfig(TbCarTypeConfigDetails details) {
        int i = tbCarTypeConfugDetaDao.updateById(details);
        if (i> 0) {
            return new CommonResult(200, "修改成功", null);
        } else {
            return new CommonResult(500, "修改失败", null);
        }
    }


}
